package org.yenn.pattern.aliyun.j2ee.mvc;

import org.junit.Test;
import org.yenn.pattern.aliyun.j2ee.entity.Student;

/**
 * 步骤 4
 * 使用 StudentController 方法来演示 MVC 设计模式的用法。
 */
public class MVCPatternDemo {
    /**
     * 步骤 5
     * 验证输出。
     *
     * Student:
     * Name: Robert
     * Roll No: 10
     * Student:
     * Name: John
     * Roll No: 10
     */
    @Test
    public void updateView() {
        //从数据可获取学生记录
        Student model = retriveStudentFromDatabase();

        //创建一个视图：把学生详细信息输出到控制台
        StudentView view = new StudentView();

        StudentController controller = new StudentController(model, view);

        controller.updateView();

        //更新模型数据
        controller.setStudentName("John");

        controller.updateView();
    }

    private static Student retriveStudentFromDatabase() {
        Student student = new Student();
        student.setName("Robert");
        student.setRollNo(10);
        return student;
    }
}